//
//  ZHomeMidCell.m
//  DoctorFAQs
//
//  Created by zjq on 17/2/28.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "ZHomeMidCell.h"
#import "CollectionViewCell.h"
#import "ZFMDBTool.h"
@interface ZHomeMidCell ()<UICollectionViewDelegate,UICollectionViewDataSource> {
    NSArray * _imageName;
    NSArray * _titleName;
    NSArray * _contextArray;
}
@property (nonatomic,strong) UICollectionView * collectionView;
@property (nonatomic,strong) NSMutableArray <UIImage *>* imageArray;
@end
@implementation ZHomeMidCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initialzeDatas];
        [self initlizeInterface];
    }
    return self;
}
- (void)initialzeDatas {
     _imageArray = [@[]  mutableCopy];
//    [self find];
   
}
- (void)initlizeInterface {
    _imageurlArray = [@[]  mutableCopy];
    _imageName = @[@"consult_doc",@"doc_answer",@"Patients",@"strategy"];
    _titleName = @[@"咨询医生",@"医生回复",@"看看病友",@"就医策略"];
    _contextArray = @[@"我们是正规公司正规！正规！",@"我们是正规公司正规！正规！",@"我们是正规公司正规！正规！",@"我们是正规公司正规！正规！"];
    [self.contentView addSubview:self.collectionView];
    
    
}

- (void)setImageurlArray:(NSMutableArray *)imageurlArray {
    _imageurlArray = imageurlArray;
    [self.collectionView reloadData];
}



// 集合视图协议
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"kJHCollectionViewIdentifier" forIndexPath:indexPath];
    if (indexPath.row == 1) {
        if ([_read isEqualToString:@"1"]) {
            cell.redView.hidden = NO;

        }else{
            cell.redView.hidden = YES;
        }
        
    }else
    {
        cell.redView.hidden =YES;
    }
    cell.imageView.image = [UIImage imageNamed:_imageName[indexPath.row]];
    cell.pimageName = _imageName[indexPath.row];
    cell.titleLabel.text = _titleName[indexPath.row];
    cell.Vname= _titleName[indexPath.row];
    cell.contextLabel.text = _contextArray[indexPath.row];
    
    if (_imageurlArray && _imageurlArray.count != 0) {
        cell.url = _imageurlArray[indexPath.row];
    }
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (self.bolck) {
        self.bolck(indexPath.item);
    }
}
- (UICollectionView *)collectionView {
    if (_collectionView) {
        return _collectionView;
    }
    UICollectionViewFlowLayout * homeLayout=[[UICollectionViewFlowLayout alloc] init];
    homeLayout.minimumLineSpacing = 1;
    homeLayout.minimumInteritemSpacing =1;
    homeLayout.itemSize = CGSizeMake(159 *xsIZE,160*ysIZE);
    homeLayout.sectionInset = UIEdgeInsetsMake(0, 0.5, 0, 0.5);
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0, SCREEN_Width, 314*ysIZE) collectionViewLayout:homeLayout];

    _collectionView.backgroundColor = KHGaryColor666;
    _collectionView.showsVerticalScrollIndicator = YES;
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.bounces = NO;
    _collectionView.scrollEnabled = NO;
    [_collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"kJHCollectionViewIdentifier"];
    NSLog(@"2222%f",_collectionView.bounds.size.height);
    return _collectionView;
}


@end
